<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<div class="wrapper wrapper-content animated fadeInRight">
	<jsp:include page="search.jsp"></jsp:include>
	<div class="row">
		<div class="col-lg-12">
			<div class="ibox ">
				<div class="ibox-title">
					<h4>采购申请列表</h4>
					<div class="ibox-tools">
						<button class="btn btn-success btn-sm" type="button" onclick="addData(null, '1')"><i class="fa fa-plus"></i>&nbsp;&nbsp;<span class="bold">批量生成月采购计划</span></button>
						<button id="searchButton" class="btn btn-default btn-sm btn-notcontrol" type="button"><i class="fa fa-search"></i>&nbsp;&nbsp;展开查询</button>
					</div>
				</div>
				<div class="ibox-content border-bottom" style="padding-bottom: 0;">
					<div class="table-responsive">
						<table class="table table-striped table-hover table-bordered border-top">
							<thead>
							<tr>
								<th width="5%">选择</th>
								<th width="5%">序号</th>
								<th>编号</th>
								<th>标题</th>
								<th>采购类型</th>
								<th>公司代码</th>
								<th>部门名称</th>
								<th>申请人</th>
								<th>采购时间</th>
								<th>期望交货时间</th>
								<th>采购原因</th>
								<th>状态</th>
								<th>附言</th>
								<th width="10%">操作</th>
							</tr>
							</thead>
							<tbody>
							<c:forEach items="${requestScope.list}" var="data" varStatus="index">
								<tr>
									<td><input type="checkbox" onclick="checkSelected(${data.id})" /></td>
									<td>${index.count}</td>
									<td>${data.code}</td>
									<td>${data.title}</td>
									<td>${requestScope.typeMap[data.type]}</td>
									<td>${data.companyCode.concat(' - '.concat(data.companyName))}</td>
									<td>${data.departmentName}</td>
									<td>${data.createUserName}</td>
									<td><fmt:formatDate value="${data.createTime}" pattern="yyyy-MM-dd"/></td>
									<td>${data.scheduledTime}</td>
									<td>${data.reason}</td>
									<td>${requestScope.statusMap[data.status]}</td>
									<td>${data.remark}</td>
									<td>
										<div class="btn-group">
											<button class="btn-white btn btn-xs btn-notcontrol" onclick="addData('${data.id}', '${data.type}')"><i class="fa fa-eye"></i>&nbsp;提交计划</button>&nbsp;
											<button class="btn-white btn btn-xs btn-notcontrol" onclick="editData('${data.id}')"><i class="fa fa-edit"></i>&nbsp;编辑</button>&nbsp;
											<button class="btn-white btn btn-xs btn-notcontrol" onclick="showData('${data.id}')"><i class="fa fa-eye"></i>&nbsp;查看</button>&nbsp;
										</div>
									</td>
								</tr>
							</c:forEach>
							</tbody>
							<tfoot>
							<jsp:include page="../../../common/pages.jsp"></jsp:include>
							</tfoot>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script src="js/listPage.js"></script>
<script>
	var selected = [];

	// 添加/移除选中数据
	function checkSelected(id) {
		let index = selected.indexOf(id);
		if (index != -1) {
			selected.splice(index, 1);
		} else {
			selected.push(id);
		}
	}

	// 提交计划
	function addData(id, type) {
		let data;
		if (id == null) {
			if (selected.length === 0) {
				redragonJS.alert("请选择需要批量生成月采购计划的数据!");
				return;
			} else {
				data = {
					subIds : selected,
					type : type
				};
			}
		} else {
			data = {
				subId : id,
				type : type
			};
		}
		redragonJS.confirm("提交后不可撤销,确认提交计划？", function() {
			$.ajax({
				type:'post',
				url : "web/purchasingAudit/save",
				contentType : "application/json",
				data : JSON.stringify(data),
				dataType : 'json',
				async : false,
				success: function (data) {
					if(data.code == 1) {
						redragonJS.alert("提交成功!");
						setTimeout(function(){
							window.location.href='web/purchasingAudit/show'
						},1000);
					} else {
						redragonJS.alert(data.msg);
					}
				}
			});
		});
	}

	// 编辑
	function editData(id) {
		window.location.href="web/purchasingAudit/getSubEdit?id=" + id;
	}

	// 详情
	function showData(id) {
		window.location.href="web/purchasingRequisition/detail?id=" + id;
	}

	//跳转页面
	function gotoPage(page){
		let data = {};
		data.page = page;
		data.code = $("#code").val();
		data.title = $("#title").val();
		data.type = $("#type").val();
		data.companyCode = $("#companyCode").val();
		data.departmentName = $("#departmentName").val();
		data.status = $("#status").val();
		var pageNumber = ${requestScope.pages.pageNumber};
		var currentPage = ${requestScope.pages.page};
		//首页和尾页无需跳转
		if((currentPage==1&&page==1)||(currentPage==pageNumber&&page==pageNumber)){

		} else {
			getsubTab(data);
		}
	}
</script>